require(["config"],function(){
    require(["jquery","template","bootstrap"],function($,template){
        function Login(){
            this.addListener();
        }

        Login.prototype = {
            addListener: function(){
                $(".btn-login").on("click",$.proxy(this.loginHandler,this));
            },

            loginHandler: function(){
                console.log(1);
                const url = "/api/users/login";

                const data = $(".form-login").serialize();

                $.get(url,data,function(data){
                    if(data.res_body.status === 1){
                        sessionStorage.username = data.res_body.data.username;
                        location.href = "/index.html";
                    }else{
                        $(".alert-danger").removeClass("hidden");
                    }
                },"json")
                return false;
            }
        }

        new Login();
    })
})